//
//  ServerIPSettingViewController.m
//  Utils
//
//  Created by enghou on 2018/4/11.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "ServerIPSettingViewController.h"
#import "NetWorkerManager.h"
#import "NumberChecker.h"
@interface ServerIPSettingViewController ()
@property (weak, nonatomic) IBOutlet UITextField *ipField;
@property (weak, nonatomic) IBOutlet UITextField *portField;
@property (weak, nonatomic) IBOutlet UIVisualEffectView *blurEffectView;

@end

@implementation ServerIPSettingViewController


- (IBAction)cancelAct:(id)sender {
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (IBAction)sureAct:(id)sender {
#pragma mark - 更换服务器配置
    if (![NumberChecker isIPAddress:self.ipField.text]) {
        [self alertSome:@"请输入一个正确的IP地址!"];
        return;
    }
    if ([self.portField.text length] > 0) {
        NSString *newip = [NSString stringWithFormat:@"http://%@:%@",self.ipField.text,self.portField.text];
        [[NetWorkerManager sharedInstance]configOtherURL:newip];
    }else{
        NSString *newip = [NSString stringWithFormat:@"http://%@",self.ipField.text];
        [[NetWorkerManager sharedInstance]configOtherURL:newip];
    }
    [self dismissViewControllerAnimated:NO completion:nil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [self.blurEffectView addGestureRecognizer:tap];
    // Do any additional setup after loading the view from its nib.
}

-(void)tap:(UITapGestureRecognizer *)tap{
    NSLog(@"点击");
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self dismissViewControllerAnimated:NO completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
